package item.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import item.bean.Car;
import item.bean.CarSort;
import item.commonresult.CommonResult;
import item.service.ICarSortService;
import item.util.Page;
@RestController
public class CarSortController {
	@Autowired
	ICarSortService ICarSortService;
	@GetMapping("selectcarsort")
	public CommonResult selectcarsort(CarSort carsort,Page page) {
        List<CarSort> a= ICarSortService.getCarSort(carsort, page);
        int count=ICarSortService.getCount(carsort);
        HashMap map=new HashMap();
        map.put("a",a);
        map.put("count",count);
         return CommonResult.success(map);
	}
	@PutMapping("editcarsort")
	public CommonResult editCarsort(@RequestBody CarSort carsort) {
		ICarSortService.editCarSort(carsort);
		CarSort c=ICarSortService.getCarSortById(carsort.getId());
		return CommonResult.success(c);
	}
	@DeleteMapping("delcarsort/{id}")
	public CommonResult delCarsort(@PathVariable int id) {
		int count =ICarSortService.deleteCarSort(id);
		return CommonResult.success(count);
	}
	@PostMapping("addcarsort")
	public CommonResult addCar(CarSort carsort) {
		ICarSortService.addCarSortMes(carsort);
		return CommonResult.success(carsort);
	}
	

}
